import numpy as np
import matplotlib.pyplot as plt 

def tanh(x):
    return (np.exp(x) - np.exp(-x)) / (np.exp(x) + np.exp(-x))

# C = np.array([-1, 1], dtype=np.float32)
# C = np.array([-1, -0.7071, 0, 0.7071, 1], dtype=np.float32)
# C = np.array([-3,-1,1,3], dtype=np.float32)
C = np.array([-7,-5,-3,-1,1,3,5,7], dtype=np.float32)

x = np.arange(-10,10,0.1)

theta = 6.2
alpha = 0.53

y = []
for i in range(len(C)-1):
    y.append(np.abs(C[i+1]-C[i])/2 * tanh(theta * ( x - alpha * (C[i]+C[i+1])/2 )))

a = np.stack(y)
y = np.sum(a,0)

# y1 = 0.7071/2 * tanh(theta * (x+kuan/2))
# y3 = -0.7071/2 * tanh(theta * (x-kuan/2))
# y = y1 + y3

_, ax1 = plt.subplots()

ax1.plot(x,y) 

ax1.grid(linestyle='--', which='both')

plt.show()



